<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>可写计算属性</title>
</head>
<body>
    <!-- 
        参考学习： https://cn.vuejs.org/guide/essentials/computed.html
    -->
    <script src="./vue.global.prod.js"></script>

    <div id="app">
        
        firstName : <input type="text" v-model="firstName" name="" id="">
        <br>
        lastName : <input type="text" v-model="lastName" name="" id="">
        <br>
        fullName : <input type="text" v-model="fullName" name="" id="">
    </div>

    <script>
        // 对象解构，从Vue对象中获取createApp函数
        const { createApp } = Vue

        // 通过createApp函数创建一个app对象
        const app = createApp({
            data() {
                return {
                    firstName: '新',
                    lastName: '唐'
                }
            },
            computed: {
                fullName: {
                    // getter
                    get() {
                        return this.firstName + ' ' + this.lastName
                    },
                    // setter
                    set(newValue) {
                        // 注意：我们这里使用的是解构赋值语法
                        [this.firstName, this.lastName] = newValue.split(' ')
                    }
                }
            }
        })

        // app对象挂载到id="app"的HTML元素，关联起来
        app.mount('#app')

    </script>

</body>
</html>